package zzc.javaWeb.javaWebHomew.utill;

import org.apache.commons.dbcp2.BasicDataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUTill {
    /**
     * 使用dbpc连接池
     *
     *
     */

    //1.创建BasicDtaSource 来创建连接池
    BasicDataSource basicDataSource = new BasicDataSource();

    //2.使用basicDataSource 来设置连接配置

    public Connection connectDataSource() throws SQLException {
        // 连接池 创建连接 ---需要四个参数
        basicDataSource.setUrl("jdbc:mysql://localhost:3306/user?serverTimezone=UTC");
        basicDataSource.setUsername("root");
        basicDataSource.setPassword("root");
        basicDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");


        Connection conn = basicDataSource.getConnection();
        //返回连接通道 供servlet使用
        return conn;
    }
}
